import numpy as np

def speedpair2wake(speedpairs, window=60, speed_thresh=0.001):
    '''
        持续一分钟以上不停运动，视为一分钟以上清醒
        否则，视为不动
    '''
    n_time = speedpairs.shape[0]
    wakes = []
    epsilon = 0.000001
    for t in range(0, n_time, window):
        idx_active = np.sum(speedpairs[t:t+window], axis=1) > speed_thresh
        if np.sum(idx_active) < window:
            wakes.extend([epsilon] * window)
        else:
            wakes.extend([1] * window)
    res = np.array(wakes)
    res = np.expand_dims(res, axis=1)
    return res

def wake30_to_sleep30(wake30):
    return 1800 - wake30 